package com.nx.qwr;

import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

/**
 * @Author: Qingwr
 * @Date: 2022/8/14 16:44
 * @Description 流量统计Reducer
 */
public class FlowCountReducer extends Reducer<Text, FlowBean, Text, FlowBean> {

    //流量累加
    @Override
    protected void reduce(Text key, Iterable<FlowBean> values, Context context) throws IOException, InterruptedException {
        FlowBean totalFB = new FlowBean();
        for (FlowBean value : values) {
            totalFB.setUpFlow(totalFB.getUpFlow() + value.getUpFlow());
            totalFB.setDownFlow(totalFB.getDownFlow() + value.getDownFlow());
            totalFB.setUpCountFlow(totalFB.getUpCountFlow() + value.getUpCountFlow());
            totalFB.setDownCountFlow(totalFB.getDownCountFlow() + value.getDownCountFlow());
        }
        context.write(key, totalFB);
    }
}
